// pages/myintegral/myintegral.js
var GlobalData = require('../../utils/GlobalData.js');
var dataManager = require('../../utils/dataManager.js');
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    myData: {},
    orderData: {},
    orderArrLen: { "first": 0, "second": 0, "third": 0 },
    showTabar: false,
    isLottery: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      showTabar: app.getConfig().isFormal,

    })
    if (app.getConfig().isLottery) {
      this.setData({
        isLottery: app.getConfig().isLottery
      })
    }
    if (GlobalData.homeData) {
      this.setData({
        myData: GlobalData.homeData
      })
    }
    dataManager.rigisterObserver("getorderscount", this.onComplete, this);
    dataManager.getOrdersAllCount(0);

  },
  onComplete() {
    dataManager.rigisterObserver("getorderscount", this.onSecond, this);
    dataManager.getOrdersAllCount(1);
  },
  onSecond() {
    dataManager.rigisterObserver("getorderscount", this.onThird, this);
    dataManager.getOrdersAllCount(2);
  },
  onThird() {
    this.setData({
      orderArrLen: GlobalData.proAllCount
    })
  },


  /**积分明细 */
  onMyIntegral() {
    dataManager.UseNavigateTo("/pages/intergralrecord/intergralrecord", false);

  },
  // GlobalData.recordType
  /**积分订单记录 */
  onOrder(e) {
    let type = e.currentTarget.dataset.type;
    if (parseInt(type) == 3) {
      dataManager.UseNavigateTo("/pages/integralconvertrecord/integralconvertrecord", false);

    } else if (type == 4) {
      // lotteryrecord
      dataManager.UseNavigateTo("/pages/integrallotteryrecord/integrallotteryrecord", false);

    }
    else {
      GlobalData.recordType = type;
      dataManager.UseNavigateTo("/pages/myorder/myorder", false);

    }
  },
  /**前往其他页面 1：购物车 2：收货地址 */
  onOtherPage(e) {
    let type = parseInt(e.currentTarget.dataset.type);
    switch (type) {
      case 1:
        dataManager.UseNavigateTo("/pages/shoppingcar/shoppingcar", false);
        break;
      case 2:
        dataManager.UseNavigateTo("/pages/addressmanage/addressmanage", false);
        break;
    }
  },
  /**退出登录 */
  onLogOut: function () {
    GlobalData.Purge()
    dataManager.UseNavigateTo("/pages/login/login", true)
  },
  goHome: function (event) {
    let index = parseInt(event.currentTarget.dataset.id)
    switch (index) {
      case 1:
        dataManager.UseNavigateTo("/pages/integralmall/integralmall", true);

        break;
      case 2:
        dataManager.UseNavigateTo("/pages/shoppingcar/shoppingcar", true);
        break;
        // case 3:
        // dataManager.UseNavigateTo("/pages/myintegral/myintegral",true);

      //   break;
    }
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})